<?php
/**
 * dAmnSock Server API
 * 
 * Provides a standardized API to the dAmn server.
 * @name dAmnSock Server API
 * @author Nol888 and Miksago
 * @license GNU General Public License
 * @copyright 2008
 * @package dAmnSock
 * @version 0.1a
 */
/**
 * dAmnSock class.
 * 
 * Can be extended via the 'extends' keyword.
 * @author Nol888
 * @copyright 2008
 * @name dAmnSock
 */
class dAmnSock {
	/**
	 * dAmn Server address
	 * @constant String DAMNSOCK_SERVER
	 */
	const DAMNSOCK_SERVER = "chat.deviantart.com";
	/**
	 * dAmn Server port
	 * @constant Int DAMNSOCK_PORT
	 */
	const DAMNSOCK_PORT = 3900;
	/**
	 * dAmn Client String
	 * @constant String DAMNSOCK_CLIENT
	 */
	const DAMNSOCK_CLIENT = "dAmnClient 0.2";
	
	/**
	 * Contains the socket used for interaction with the server.
	 *
	 * @var Object
	 */
	public $socket;
	/**
	 * Contains the number of bytes sent throughout the entire connection.
	 *
	 * @var Int/Long
	 */
	public $byteCount;
	/**
	 * Are we connected or not?
	 *
	 * @var Boolean
	 */
	public $connected;
	
	/**
	 * Sends a raw packet, but adds a null character to the end.
	 * 
	 * @author Nol888
	 * @access private
	 * @version 0.1a
	 * @param string $data The data to send.
	 * @return null
	 */
	private function sendPacket( $data ) {
		$data .= chr(0);
		if (strlen($data) >= 7000) {
			$data = substr($data, 0, 7000);
			$data .= " [Message Truncated]" . chr(0);
		}
		socket_send($this->socket, $data, strlen($data), 0x0);
		socket_clear_error($socket);
		$this->byteCount += strlen($data);
	}
	
}
?>